import Redirect from '@/view/main/Redirect.vue'
import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  { path: '/', redirect: '/redirect' },
  { name: 'Redirect', path: '/redirect', component: Redirect },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes: routes
})

router.beforeEach((to, from, next) => {
  const token = localStorage.getItem("token")
  if (to.path !== '/redirect' && !token) {
    next('/')
  } else {
    next()
  }
})

export default router
